package com.hnevc.acountms.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hnevc.acountms.R;
import com.hnevc.acountms.activity.InaccountInfoManageActivity;
import com.hnevc.acountms.model.Tb_inaccount;

import java.util.List;

/**
 * Created by Administrator on 2017/9/29.
 */

public class InaccountInfoAdapter extends RecyclerView.Adapter<InaccountInfoAdapter.MyViewHolder> {
    Context mContext;
    List<Tb_inaccount> mInaccounts;

    public InaccountInfoAdapter(Context context, List<Tb_inaccount> inaccounts) {
        mContext = context;
        mInaccounts = inaccounts;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view  = LayoutInflater.from(mContext)
                .inflate(R.layout.inaccountinfo_list_item,parent,false);
        MyViewHolder viewHolder = new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        Tb_inaccount inaccount = mInaccounts.get(position);
        holder.mTvId.setText(inaccount.getId()+"");
        holder.mTvType.setText(inaccount.getType());
        holder.mTvMoney.setText(inaccount.getMoney()+"");
        holder.mTvTime.setText(inaccount.getTime());
    }

    @Override
    public int getItemCount() {
        return mInaccounts.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView mTvId;
        TextView mTvType;
        TextView mTvMoney;
        TextView mTvTime;

        public MyViewHolder(View itemView) {
            super(itemView);
            mTvId = (TextView) itemView.findViewById(R.id.id_tv_id);
            mTvType = (TextView) itemView.findViewById(R.id.id_tv_type);
            mTvMoney = (TextView) itemView.findViewById(R.id.id_tv_money);
            mTvTime = (TextView) itemView.findViewById(R.id.id_tv_time);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int position = getAdapterPosition();
                    int index  = mInaccounts.get(position).getId();
                    Intent intent = new Intent(mContext
                            , InaccountInfoManageActivity.class);
                    intent.putExtra("index",index);
                    mContext.startActivity(intent);
                }
            });
        }
    }
}
